package com.zj.study.utils.beancopier;

import lombok.Data;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>Title: BeanCopierTest</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2024 版权</p>
 * <p>Company: Oceanpayment</p>
 *
 * @author Jerry Zhao
 * @version V1.0
 * @date 2024年07月16号 14点16分40秒
 */
public class BeanCopierTest {


    public static void main(String[] args) {
        A a = new A();
        a.setAge(18);
        a.setName("zj");
        a.setEmail("zj@163.com");
        a.setSalary(new BigDecimal("1000.01"));

        C c = new C();
        c.setAge(18);
        c.setName("zj");
        c.setEmail("zj@oceanpayment.com");
        c.setAddress("1111111111111111");
        a.setC(c);


        A a1 = new A();
        a1.setAge(19);
        a1.setName("zj1");
        a1.setEmail("zj1@qq.com");
        a1.setSalary(new BigDecimal("10000.01"));

        List<A> soureList = List.of(a, a1);

        // copy one
        B b = BeanCopier.copy(a, B.class);
        System.out.println("b = " + b);

        // copy list
        List<B> copyList = BeanCopier.copyList(soureList, B.class);
        System.out.println("copyList = " + copyList);

        // copy list and callback
        List<B> copyList1 = BeanCopier.copyList(soureList, B.class, (source, target) -> {
            if (source.getSalary() != null) {
                target.setSalary(source.getSalary().toString());
            }
        });
        System.out.println("copyList1 = " + copyList1);
    }


    @Data
    @Accessors(chain = true)
    public static class A{
        private String name;
        private Integer age;
        private String email;
        private BigDecimal salary;
        private C c;
    }

    @Data
    @Accessors(chain = true)
    public static class B{
        private String name;
        private Integer age;
        private String email;
        private String address;
        private String salary;
        private C c;
    }

    @Data
    @Accessors(chain = true)
    public static class C {
        private String name;
        private Integer age;
        private String email;
        private String address;
    }


}